const http = require('http');
const fs = require('fs');
const path = require('path');
const app = http.createServer((req, res) => {
    // res.setHeader('content-type', 'text/html;charset=utf-8');
    if (req.url === '/' || req.url === '/index.html') {
        let str = fs.readFileSync(__dirname + '/public/index.html');
        res.end(str);
    }
    if(req.url === '/admin.html'){
       fs.readFile(path.resolve(__dirname,'./public/admin.html'),(err,data)=>{
           if(err){
            res.end('读取文件失败');
           }else{
               res.end(data);
           }
       })
    }
    if(req.url === '/css/main.css'){
        fs.readFile(__dirname+'/public/css/main.css',(err,data)=>{
            if(err)return;
            res.end(data);
        });
    }
    if(req.url === '/abc.png'){
      let str =  fs.readFileSync(path.resolve(__dirname,'./public/img/1.png'));
      res.end(str);
    }
})
app.listen(80, () => {
    console.log("启动成功");
})